See Also

SegmentedStream Class  | SegmentedStream Members  | Overload List

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows ME, Windows 2000, Windows XP, Windows Server 2003, Windows Vista

Language

Visual Basic

C#

C++

C++/CLI

Show All

buffer
The storage location for the received data.
delimiter
The token that is used to determine a segment was read.
offset
The zero-based position in the buffer at which to store the received data.
count
The maximum number of bytes to read.
found
callback
The AsyncCallback delegate to be called when the operation is complete.
state
An object containing state information for this operation.
See Also Languages PowerTCP Email Validation for .NET

BeginRead(Byte[],Byte[],Int32,Int32,Boolean,AsyncCallback,Object) Method

Dart.PowerTCP.EmailValidation Namespace > SegmentedStream Class > BeginRead Method : BeginRead(Byte[],Byte[],Int32,Int32,Boolean,AsyncCallback,Object) Method

Begins an asynchronous read from the stream that completes when the provided delimiter is found, count bytes have been read, or end of stream is reached.

[Visual Basic]
Overloads Public Overridable Function BeginRead( _    ByVal buffer() As Byte, _    ByVal delimiter() As Byte, _    ByVal offset As Integer, _    ByVal count As Integer, _    ByRef found As Boolean, _    ByVal callback As AsyncCallback, _    ByVal state As Object _ ) As IAsyncResult
[C#]
public virtual IAsyncResult BeginRead(    byte[] buffer,    byte[] delimiter,    int offset,    int count,    ref bool found,    AsyncCallback callback,    object state );
[C++]
public: virtual IAsyncResult* BeginRead(    byte[]* buffer,    byte[]* delimiter,    int offset,    int count,    ref bool found,    AsyncCallback* callback,    Object* state )
[C++/CLI]
public: virtual IAsyncResult^ BeginRead(    bytearray<buffer>^ buffer,    bytearray<delimiter>^ delimiter,    int offset,    int count,    % bool found,    AsyncCallback^ callback,    Object^ state )

Parameters

buffer
The storage location for the received data.
delimiter
The token that is used to determine a segment was read.
offset
The zero-based position in the buffer at which to store the received data.
count
The maximum number of bytes to read.
found
callback
The AsyncCallback delegate to be called when the operation is complete.
state
An object containing state information for this operation.

Return Type

An IAsyncResult representing the asynchronous operation. To determine how many bytes were read, you must pass this IAsyncResult to the EndRead method of the stream. This should be done within your AsyncCallback event handler.

Exceptions

ExceptionDescription
IOExceptionThrown when the stream is not Readable.
ArgumentNullExceptionThrown when the buffer, delimiter or callback is null.
ArgumentOutOfRangeExceptionThrown when the offset is less than zero or when count is less than or equal to zero.
ArgumentExceptionThrown when the (offset + count) > buffer.Length, or delimiter.Length == 0, or delimiter.length > count.

Remarks

The purpose of this method is to provide a convenient way to read a variable-length record from the stream. The EndRead method should be called when your AsyncCallback delegate is raised.

Example

The following example demonstrates asynchronously reading from the server using the stream interface. This involves creating a callback method in which the response is handled. If you would like to use fully asynchronous methods with events already implemented, try the low-level interface (Tcp.BeginRead & Tcp.BeginWrite).

[C#] 


private void AsynchronousReadTest()
{
  
// Connect to the server
  
tcp1.Connect("atropos", 13);

  
// DAYTIME protocol (port 13) sends data and closes, receive data.
  
// This demonstrates receiving data asynchronously using the stream interface.
           
  
// data buffer is a global variable
  
databuffer = new byte[tcp1.ReceiveBufferSize];

  
// Begin the asynchronous Read operation.
  
tcp1.Stream.BeginRead(databuffer, 0, tcp1.ReceiveBufferSize, new System.AsyncCallback(MyCallback), null);
}

private void MyCallback(System.IAsyncResult ar)
{
  
// End pending asynchronous request.
  
if(ar.IsCompleted)
     tcp1.Stream.EndRead(ar);

  
// Write result
  
Debug.WriteLine(System.Text.Encoding.Default.GetString(databuffer));
}
                

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows ME, Windows 2000, Windows XP, Windows Server 2003, Windows Vista

See Also

SegmentedStream Class  | SegmentedStream Members  | Overload List


Send comments on this topic.

Documentation version 1.0.3.0.

© 2008 Dart Communications.  All rights reserved.